import { getAction, deleteAction, putAction, postAction, httpAction } from '@/api/manage'
import Vue from 'vue'
import { UI_CACHE_DB_DICT_DATA } from '@/store/mutation-types'
import { axios } from '../utils/request'

const apiBaseUrl = `${window.location.protocol}//${window.location.host}` + '/law-boot'

//角色管理
const addRole = (params) => postAction('/sys/role/add', params)
const editRole = (params) => putAction('/sys/role/edit', params)
const queryall = (params) => getAction('/sys/role/queryall', params)
const addMinorCareActivities = (params) => postAction('/MinorRecordAddition/addMinorCareActivities', params)

//用户管理
const addUser = (params) => postAction('/sys/user/add', params)
const editUser = (params) => putAction('/sys/user/edit', params)
const queryUserRole = (params) => getAction('/sys/user/query_user_role', params)
const getUserList = (params) => getAction('/sys/user/list', params)
const frozenBatch = (params) => putAction('/sys/user/frozen_batch', params)

//验证用户是否存在
const checkOnlyUser = (params) => getAction('/sys/user/checkOnlyUser', params)

//改变密码
const changePassword = (params) => putAction('/sys/user/change_password', params)

//权限管理
const addPermission = (params) => postAction('/sys/permission/add', params)
const editPermission = (params) => putAction('/sys/permission/edit', params)
const getPermissionList = (params) => getAction('/sys/permission/tree', params)
const getSystemMenuList = (params) => getAction('/sys/permission/getSystemMenuList', params)
const getSystemSubmenu = (params) => getAction('/sys/permission/getSystemSubmenu', params)
const getSystemSubmenuBatch = (params) => getAction('/sys/permission/getSystemSubmenuBatch', params)
const queryTreeList = (params) => getAction('/sys/permission/query_tree', params)
const queryTreeListForRole = (params) => getAction('/sys/permission/query_tree', params)
const queryListAsync = (params) => getAction('/sys/permission/queryListAsync', params)
const queryRolePermission = (params) => getAction('/sys/permission/query_role_permission', params)
const saveRolePermission = (params) => postAction('/sys/permission/save_role_permission', params)
const queryPermissionsByUser = () => getAction('/sys/permission/get_user_permission_by_token', { timeout: 50000 })
const loadAllRoleIds = (params) => getAction('/sys/permission/loadAllRoleIds', params)
const getPermissionRuleList = (params) => getAction('/sys/permission/getPermRuleListByPermId', params)
const queryPermissionRule = (params) => getAction('/sys/permission/queryPermissionRule', params)

// 部门管理
const queryDepartTreeList = (params) => getAction('/sys/police_agency/tree', params)
const queryDepartTreeSync = (params) => getAction('/sys/sysDepart/queryDepartTreeSync', params)

// 区域管理
// const queryDepartTreeList = (params) => getAction("/sys/sysDepart/queryTreeList", params)
// const queryIdTree = (params) => getAction('/sys/sysDepart/queryIdTree', params)
const addArea = (params) => postAction('/sys/police_agency/add', params)
const queryParentName = (params) => getAction('/sys/sysDepart/queryParentName', params)
const deleteByDepartId = (params) => deleteAction('/sys/police_agency/delete', params)

//数据字典
const addDict = (params) => postAction('/sys/dict/add', params)
const editDict = (params) => putAction('/sys/dict/edit', params)
const addDictItem = (params) => postAction('/sys/dict_item/add', params)
const editDictItem = (params) => putAction('/sys/dict_item/edit', params)

//字典标签专用（通过code获取字典数组）
export const ajaxGetDictItems = (params) => getAction(`/sys/dict/find_enable_dict_items_by_code`, params)
export const getAllDict = (params) => getAction(`/sys/dict/find_all_dict`, params)
//获取风险等级

//从缓存中获取字典配置
function getDictItemsFromCache(dictCode) {
  if (Vue.ls.get(UI_CACHE_DB_DICT_DATA) && Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode]) {
    let dictItems = Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode]
    return dictItems
  }
}

// 根据部门主键查询用户信息
const queryUserByDepId = (params) => getAction('/sys/user/queryUserByDepId', params)

// 重复校验
const duplicateCheck = (params) => getAction('/sys/duplicate/check', params)
// 加载分类字典
const checkRuleByCode = (params) => getAction('/sys/checkRule/checkByCode', params)

//获取验证码
const randomImage = (params) => getAction('/sys/random/image')
// 检查验证码
const checkCaptcha = (params) => postAction('/sys/random/check_captcha', params)

//树形结构
const getOneFlagTreeList = (params) => getAction('/sys/police_agency/user_tree', params) // 用户所属区域的机关机构
// const getOneFlagTreeList = (params) => getAction('/web/self/sys_depart/user_depart_office_tree', params) // 用户所属区域的机关机构
const getOneFlagTreeList2 = (params) => getAction('/web/self/sys_depart/all_depart_tree', params) // 区域管理
const getOneFlagTreeList3 = (params) => getAction('/web/self/sys_depart/all_depart_office_tree', params) // 机关机构

//富文本上传图片/视频
const uploadUeditorImg = (params) => postAction('/sys/upload/upload_file', params)

// 上传图片
const uploadFile = (params) => postAction('/sys/upload/upload_file', params)
const excelImport1 = (params) => postAction('/excel/uploadQnMinor', params)
//获取图片路径前缀
const findEnableDictItemsbyCode = (params) => getAction('/sys/dict/find_enable_dict_items_by_code', params)

// 刷新token
const handelRefreshToken = (params) => postAction('/sys/operate/refresh_token', params)
export const getKeynoteInfo = ({ params, data, timeout = 50000 }) =>
  axios({
    url: `${apiBaseUrl}/Instruction/Keynote/getKeynoteInfo`,
    method: 'post',
    excludeBaseURL: true,
    params,
    data,
  })
const excelImport = (formData) =>
  axios({
    url: `${apiBaseUrl}/excel/uploadQnMinor`,
    method: 'post',
    excludeBaseURL: true,
    data: formData,
  })

export const getSubordinateList = (params) =>
  axios({
    url: `${apiBaseUrl}/common/commons/subordinateList`,
    method: 'get',
    excludeBaseURL: true,
    params,
  })

export const getRiskLevels = (params) =>
  axios({
    url: `${apiBaseUrl}/common/commons/getRiskLevels`,
    method: 'get',
    excludeBaseURL: true,
    params,
  })
export const getBadBehaviorList = (params) =>
  axios({
    url: `${apiBaseUrl}/common/MinorRecordSelect/selectMinorBadBehaviorPage`,
    method: 'get',
    excludeBaseURL: true,
    params,
  })
export const getBadBehavior = (params) =>
  axios({
    url: `${apiBaseUrl}/common/commons/getBehaviorTypes`,
    method: 'get',
    excludeBaseURL: true,
    params,
  })

export const getCommunityList = (params) =>
  axios({
    url: `${apiBaseUrl}/common/commons/getCommunityList`,
    method: 'get',
    excludeBaseURL: true,
    params,
  })
export const getCarePersonList = (params) =>
  axios({
    url: `${apiBaseUrl}/common/MinorRecordSelect/selectMinorCareTeamPage`,
    method: 'get',
    excludeBaseURL: true,
    params,
  })
//两青模块

export const houseDetails = (params) => getAction('/house/houseDetails', params)

export const webpopulationDetails = (params) => getAction('/indeed/population/webpopulationDetails', params)
export const companyWebDetails = (params) => getAction('/company/message/webDetails', params)
export const rentingHouseDetails = (params) => getAction('/rentinghouse/rentingHouseDetails', params)
export const contractDetails = (params) => getAction('/rentinghouse/contractDetails', params)

export const webMachineRepairRecordDetails = (params) => getAction('/industry/webMachineRepairRecordDetails', params)
export const machinePrintRecordDetails = (params) => getAction('/industry/machinePrintRecordDetails', params)
export const pawnRecordDetails = (params) => getAction('/industry/pawnRecordDetails', params)
export const wasteRecyclingRecordDetails = (params) => getAction('/industry/wasteRecyclingRecordDetails', params)
export const oilSaleRecordDetails = (params) => getAction('/industry/oilSaleRecordDetails', params)
export const getIdUnlockRecord = (params) => getAction('/industry/getIdUnlockRecord', params)
export const getIdPhoneRecyclingRecord = (params) => getAction('/industry/getIdPhoneRecyclingRecord', params)

export const secondStandardLogin = (params) => postAction('/sys/user/secondStandardLogin', params)

export const permissionPdataTree = (params) => postAction('/sys/permission/pdateTree', params)
export const auxiliaryUserResetInitializingState = (params) =>
  putAction('/police/auxiliary_user/resetInitializingState', undefined, params)
export const gridUserResetInitializingState = (params) =>
  putAction('/police/grid_user/resetInitializingState', undefined, params)

export const editDeviceId = (params) => postAction('/police/user/editDeviceId', params)

export const documentPage = (params) => getAction('/sys/document/page', params)

export const phoneDetails = (params) => getAction('/registered/phone/details', params)
export const electricvehiclesDetails = (params) => getAction('/registered/electricvehicles/details', params)
export const documentUpdateDisable = (params) => getAction('/sys/document/updateDisable', params)
export const storagebatteryAcquisitionRecordsDetails = (params) =>
  getAction('/industry/storagebatteryAcquisitionRecords/details', params)

export const electricvehiclesAcquisitionRecordsDetails = (params) =>
  getAction('/industry/electricvehiclesAcquisitionRecords/details', params)

export const phoneAcquisitionRecordsDetails = (params) => getAction('/industry/phoneAcquisitionRecords/details', params)

export const deviceDetails = (params) => getAction('/wb/device/deviceDetails', params)
export const deviceTrajectory = (params) => getAction('/wb/device/deviceTrajectory', params)
export const deviceHelpInfoList = (params) => getAction('/wb/device/deviceHelpInfoList', params)

export const mentalpatientDeviceDetails = (params) => getAction('/wb/mentalpatient/deviceDetails', params)
//两青模块
export const selectMinorpageDetails = (params) => getAction('/qnMinor/selectMinorpageDetails', params)

export const helpinfoHelpInfoDetails = (params) => getAction('/wb/helpinfo/helpInfoDetails', params)
export const getPoliceByTwoCharacter = (params) => getAction('/police/user/getPoliceByTwoCharacter', params)
export const deviceBingding = (params) => postAction('/wb/device/bingding', params)
export const mentalpatientBingding = (params) => postAction('/wb/mentalpatient/bingding', params)

export const deviceDeviceMap = (params) => getAction('/wb/device/deviceMap', params)

export const wbHttpFences = (params) => postAction('/wb/wbHttp/fences', params)

export const deviceinfoSetFance = (params) => getAction('/wb/device/setFance', params)

export const setResponsiblePerson = (params) => postAction('/wb/device/setResponsiblePerson', params)
export const earlyWarningPage = (params) => getAction('/wb/device/earlyWarningPage', params)
export const deviceAnalysis = (params) => postAction('/wb/device/analysis', params)
export const wbHttpRestart = (params) => getAction('/wb/wbHttp/restart', params)

export const wbDataStatistics = (params) => getAction('/wb/data/show/wbDataStatistics', params)
export const dataClassified = (params) => getAction('/wb/data/show/dataClassified', params)

export const feedbackDetail = (params) => getAction('/feedback/detail', params)

export const feedbackAdd = (params) => postAction('/feedback/add', params)

export {
  // imgView,
  // doMian,
  addRole,
  editRole,
  addUser,
  editUser,
  queryUserRole,
  getUserList,
  queryall,
  frozenBatch,
  checkOnlyUser,
  changePassword,
  getPermissionList,
  addPermission,
  editPermission,
  queryTreeList,
  queryListAsync,
  queryRolePermission,
  saveRolePermission,
  queryPermissionsByUser,
  loadAllRoleIds,
  getPermissionRuleList,
  queryPermissionRule,
  queryDepartTreeList,
  queryDepartTreeSync,
  addDict,
  editDict,
  addDictItem,
  editDictItem,
  queryUserByDepId,
  duplicateCheck,
  queryTreeListForRole,
  getSystemMenuList,
  getSystemSubmenu,
  getSystemSubmenuBatch,
  checkRuleByCode,
  getDictItemsFromCache,
  randomImage,
  checkCaptcha,
  addArea,
  // queryIdTree,
  queryParentName,
  deleteByDepartId,
  getOneFlagTreeList,
  getOneFlagTreeList2,
  getOneFlagTreeList3,
  uploadUeditorImg,
  uploadFile,
  findEnableDictItemsbyCode,
  handelRefreshToken,
  excelImport,
  addMinorCareActivities,
}
